package com.test.base.utils;

import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class HttpRestTemplet {
    @Autowired
    private CloseableHttpClient closeableHttpClient;

    public HttpRestTemplet() {
    }

    @Bean(name = "restTemplate")
    public  RestTemplate createRestTemplate() {
        CloseableHttpClient httpClient = closeableHttpClient;
        HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
        return new RestTemplate(clientHttpRequestFactory);
    }
}
